<?php

/**
 * This is the model class for table "kereta_api".
 *
 * The followings are the available columns in table 'kereta_api':
 * @property integer $ID_KERETA
 * @property string $NAMA_KERETA
 * @property string $USERNAME_KERETA
 * @property string $PASSWORD_KERETA
 *
 * The followings are the available model relations:
 * @property DetailPerjalananKereta[] $detailPerjalananKeretas
 * @property Promosi[] $promosis
 */
class KeretaApi extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return KeretaApi the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'kereta_api';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('ID_KERETA, NAMA_KERETA', 'required'),
			array('ID_KERETA', 'numerical', 'integerOnly'=>true),
			array('NAMA_KERETA', 'length', 'max'=>25),
			array('USERNAME_KERETA', 'length', 'max'=>20),
			array('PASSWORD_KERETA', 'length', 'max'=>100),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('ID_KERETA, NAMA_KERETA, USERNAME_KERETA, PASSWORD_KERETA', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'detailPerjalananKeretas' => array(self::HAS_MANY, 'DetailPerjalananKereta', 'ID_KERETA'),
			'promosis' => array(self::HAS_MANY, 'Promosi', 'ID_KERETA'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ID_KERETA' => 'Id Kereta',
			'NAMA_KERETA' => 'Nama Kereta',
			'USERNAME_KERETA' => 'Username Kereta',
			'PASSWORD_KERETA' => 'Password Kereta',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('ID_KERETA',$this->ID_KERETA);
		$criteria->compare('NAMA_KERETA',$this->NAMA_KERETA,true);
		$criteria->compare('USERNAME_KERETA',$this->USERNAME_KERETA,true);
		$criteria->compare('PASSWORD_KERETA',$this->PASSWORD_KERETA,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}